//
// Created by yangchao on 2022/5/6.
// 48. 旋转图像: https://leetcode-cn.com/problems/rotate-image/
//
#include <vector>
using namespace std;

class Rotate{
public:
    void rotate(vector<vector<int>>& matrix) {
        int len = matrix.size();
        for (int i = 0; i < len / 2; ++i) {
            //注意循环终止条件
            for (int j = 0; j < (len+1)/2; ++j) {   //盯住一个元素来观察规律，比如matrix[1][0] = 2;
                int temp = matrix[i][j];
                matrix[i][j] = matrix[len-1-j][i];
                matrix[len-1-j][i] = matrix[len-1-i][len-1-j];
                matrix[len-1-i][len-1-j] = matrix[j][len-1-i];
                matrix[j][len-1-i] = temp;
            }
        }
    }
};

